<%--
  Created by IntelliJ IDEA.
  User: 文鹏
  Date: 2022/1/6
  Time: 11:51
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>入库申请登记</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://unpkg.com/bootstrap-table@1.15.3/dist/bootstrap-table.min.css">
    <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
    <script src="https://unpkg.com/bootstrap-table@1.15.3/dist/bootstrap-table.min.js"></script>
    <script src="../js/bootstrap-table-zh-CN.min.js"></script>
</head>
<body>
<DIV class=DIV_STYLE2 style="display: block" id="div2"><TABLE cellSpacing=0 cellPadding=0 width=1000 align=center bgColor=#ffffff border=0 >
    <div style="position: relative;left: 60%">

        <INPUT   data-toggle="modal" data-target="#myModal"  type=button value=添加工序>
        <INPUT  onclick=delSelect() type=button value=删除工序>
        <INPUT  onclick=addRk() id="tj" type=button value=提交>
        <INPUT   onclick="yl()" type=button value=预览>
        <INPUT onmouseup="this.className='btn3_mouseup'" onclick=fanhui() onmouseover="this.className='btn3_mouseover'" onmousedown="this.className='btn3_mousedown'" onmouseout="this.className='btn3_mouseout'" class=btn3_mouseout type=button value=返回>
    </div>
    <TBODY>
    <TR>
        <TD class=TABLE_STYLE6 vAlign=bottom rowSpan=2 align=center>
            <TABLE style="BORDER-TOP: #333333 1px solid; BORDER-RIGHT: #333333 1px solid; BORDER-BOTTOM: #333333 1px solid; BORDER-LEFT: #333333 1px solid" cellSpacing=0 cellPadding=0 width="100%" border=0>
                <TBODY>
                <TR>
                    <TD height=10 colSpan=4>
                        <TABLE width="100%">
                            <TBODY>
                            <TR>
                                <TD>
                            <table align="center">
                                <tr>
                                    <td><h3>入库申请单</h3></td>
                                </tr>
                            </table>
                                    <br>
                                 <div>
                                     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                     <span >入库人:<span><input type="text" style="border-bottom: 1px solid #000000;border-left: 0px;border-top: 0px;border-right: 0px;width: 40%;outline:none"></span></span>
                                     <span style="position: relative;left:50px;">入库理由: <select name="" id="rkly">
                                         <option value="R001-1">生产入库</option>
                                         <option value="R001-2">库存初始</option>
                                         <option value="R001-3">赠送</option>
                                         <option value="R001-4">内部归还</option>
                                         <option value="R001-5">其他归还</option>
                                     </select></span>
                                     <br>
                                     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                     <span>是否退回: <select name="">
                                         <option value="">是</option>
                                         <option value="">否</option>
                                     </select></span>
                                     <span style="position: relative;left:350px;">回退时间:<span><input type="date" style="border-bottom: 1px solid #000000;border-left: 0px;border-top: 0px;border-right: 0px;width: 40%;outline:none" id="sj"></span></span>
                                 </div>
                                    <br>
                                    <TABLE id=tableOnlineEdit class=TABLE_STYLE5 borderColor=#000000 cellSpacing=0 cols=1 borderColorDark=#eeeeee cellPadding=0 align=center borderColorLight=#848284 border=1><THEAD>
                                    <TR class=TR_STYLE2 height="10" bgColor=#d2e9ff>
                                        <TD class=TD_STYLE2 borderColor=#dedbd6 width="7%" align=left>点选</TD>
                                        <TD class=TD_STYLE2 borderColor=#dedbd6 width="13%" align=left>产品名称</TD>
                                        <TD class=TD_STYLE2 borderColor=#dedbd6 width="13%" align=left>产品编号</TD>
                                        <TD class=TD_STYLE2 borderColor=#dedbd6 width="7%" align=left>产地</TD>
                                        <TD class=TD_STYLE2 borderColor=#dedbd6 width="11%" align=left>入库数</TD>
                                        <TD class=TD_STYLE2 borderColor=#dedbd6 width="11%" align=left>成本单价</TD>
                                        <TD class=TD_STYLE2 borderColor=#dedbd6 width="13%" align=left>小计</TD>
                                    </TR>
                                    </THEAD>
                                        <TBODY></TBODY>
                                    </TABLE>
                                    <br>
                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                    <span>总件数:
                                         <span><input type="text" style="border-bottom: 1px solid #000000;border-left: 0px;border-top: 0px;border-right: 0px;width: 40%;outline:none" id="sum"></span></span>
                                    <span style="position: relative;left:50px;">总金额:<span><input type="text" style="border-bottom: 1px solid #000000;border-left: 0px;border-top: 0px;border-right: 0px;width: 40%;outline:none" id="je"></span></span>
                                    <br>
                                    <div>
                                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        <span>登记人:<input style="border-bottom: 1px solid #000000;border-left: 0px;border-top: 0px;border-right: 0px;width: 40%;outline:none"></span>
                                        <span style="position: relative;left:50px;">登记时间: <span></span> </span>
                                    </div>

                                    <br>

                                    <div>
                                        <div>
                                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                            <span style="position: relative;top: -40px">备注:</span><textarea style="resize: none" rows=4 cols="100" ></textarea>
                                        </div>
                                    </div>
                                </TD></TR></TBODY></TABLE></TD></TR>
                            <TR>
                                <TD width=56 colSpan=3 noWrap></TD></TR>
                            <TR>
                                <TD height=100 colSpan=3 noWrap></TD>
                                <TD></TD></TR>
                            <TR vAlign=bottom>
                                <TD colSpan=4 noWrap align=center></TD></TR></TD>
                            <TR>
                                <TD colSpan=4 noWrap align=right></TD></TR></TBODY></TABLE></TD>
                    <TD bgColor=#ffffff height=2 width=1></TD>
                    <TD bgColor=#ffffff height=2 width=1></TD>
                    <TD bgColor=#ffffff height=2 width=1></TD></TR>
                <TR>
                    <TD bgColor=#333333 height=120 width=1></TD>
                    <TD bgColor=#666666 height=120 width=1></TD>
                    <TD bgColor=#999999 height=120 width=1></TD></TR>
                <TR align=right vAlign=top>
                    <TD colSpan=4>
                        <TABLE class=TABLE_STYLE6 cellSpacing=0 cellPadding=0 align=center border=0>
                            <TBODY>
                            <TR>
                                <TD bgColor=#333333 height=1></TD></TR>
                            <TR>
                                <TD bgColor=#666666 height=1></TD></TR>
                            <TR>
                                <TD bgColor=#999999 height=1></TD></TR></TBODY></TABLE></TD></TR>
                <TR align=right vAlign=middle>
                    <TD colSpan=4></TD></TR></TBODY></TABLE></DIV>



<!-- 模态框 -->
<div class="modal fade" id="myModal">
    <div class="modal-dialog">
        <div class="modal-content">

            <!-- 模态框头部 -->
            <div class="modal-header">
                <h4 class="modal-title"></h4>
                <button type="button" class="close" data-dismiss="modal">&times;</button>
            </div>

            <!-- 模态框主体 -->
            <div class="modal-body">
                <table border="1px" id="table" cellspacing="0" cellpadding="0" width="400px">
                </table>
            </div>

            <!-- 模态框底部 -->
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
            </div>

        </div>
    </div>
</div>
<script>
    $(function () {
        $("#table").bootstrapTable({
            method:"get",
            contentType:"application/json",
            url:"http://localhost:8080/ck/dfileUp",
            striped:true,
            pageNumber:1,
            pagination:true,
            sidePagination:"server",
            pageSize:5,
            pageList:[3,5,7,10],
            queryParams:function (param) {
                return {
                    page: (param.offset / param.limit) + 1,
                    pageNum: param.limit,
                    designCellTag:"K001-1",
                }
            },
            columns:[
                {title:"产品编号",field:"productId",align:"center"},
                {title:"产品名称",field:"productName",align:"center"},
                {title:"产地",field:"factoryName",align:"center"},
                {title:"单价",field: "listPrice",align:"center"},
                {title:"操作",field:"id",align:"center",formatter:function (value,row) {
                        var btn1="<button class='btn btn-primary btn-sm'  onclick=update('"+row.productId+"','"+row.productName+"','"+row.factoryName+"','"+row.listPrice+"')>添加</button>";
                        return btn1
                    }}
            ]
        })
    })


    function update(zz1,zz2,zz3,zz4) {
        let zz = document.getElementsByClassName("zz2");
        if(zz.lenght>0){
            for(var i=0;i<zz.lenght;i++){
                if(zz[i]==zz2){
                    return false;
                }else {
                    document.getElementById("tableOnlineEdit").innerHTML +=
                        "<tr>" +
                        "<td><input type='checkbox' name='car'></td>" +
                        "<td><span  class='zz2'>" + zz2 + "</span></td>" +
                        "<td class='zz1'>" + zz1 + "</td>" +
                        "<td class='zz3'>" + zz3 + "</td>" +
                        "<td><input type='text' class='zz5' value='1'></td>" +
                        "<td class='zz4'>" + zz4 + "</td>" +
                        "<td class='zz6'></td>" +
                        "</tr>"
                }
            }
        }else {
            document.getElementById("tableOnlineEdit").innerHTML +=
                "<tr>" +
                "<td><input type='checkbox' name='car'></td>" +
                "<td><span  class='zz2'>" + zz2 + "</span></td>" +
                "<td class='zz1'>" + zz1 + "</td>" +
                "<td class='zz3'>" + zz3 + "</td>" +
                "<td><input type='text' class='zz5' value='1'></td>" +
                "<td class='zz4'>" + zz4 + "</td>" +
                "<td class='zz6'></td>" +
                "</tr>"
        }

    }
    //删除工序
    function delSelect() {
        let car = document.getElementsByName("car");
        for(let i=car.length-1;i>=0;i--){
           if (car[i].checked==true){
                car[i].parentNode.parentNode.remove();
           }
        }
    }

    function yl() {
        var aa=0;
        var bb=0;
        let zz4 = document.getElementsByClassName("zz4");
        let zz5 = document.getElementsByClassName("zz5");
        let zz6 = document.getElementsByClassName("zz6");
        for (let i=0;i<zz4.length;i++){
            aa+=1;
            zz6[i].innerHTML=parseInt(zz4[i].innerHTML)*parseInt(zz5[i].value);
            bb+=parseInt(zz4[i].innerHTML)*parseInt(zz5[i].value);
        }
        $("#sum").val(aa);
        $("#je").val(bb);
    }
    function addRk() {
        let productId = document.getElementsByClassName("zz1");
        let productName =  document.getElementsByClassName("zz2");
        let productDescribe =  document.getElementsByClassName("zz3");
        let costPrice =  document.getElementsByClassName("zz4");
        let amount =  document.getElementsByClassName("zz5");


        let reason = $("#rkly").val();
        let amountSum= $("#sum").val();
        let costPriceSum = $("#je").val();
        let checkTag="S001-0";
        let storeTag="K002-1";
        $.getJSON("http://localhost:8080/ck/addRkk",{reason:reason,amountSum:amountSum,costPriceSum:costPriceSum,checkTag:checkTag,storeTag:storeTag},function (date) {
        })
        for (var i=0;i<productId.length;i++){
            $.getJSON("http://localhost:8080/ck/addRk",{productId:productId[i].innerHTML,productName:productName[i].innerHTML,productDescribe:productDescribe[i].innerHTML,costPrice:costPrice[i].innerHTML,amount:amount
                    [i].value},function (date) {
                    console.log(date)
            })
        }

    }
</script>
</body>
</html>
